﻿@using ABC.Controllers.ViewModels.My
@model ObjectInsuranceViewModel
@{
    ViewBag.Title = string.IsNullOrEmpty(Model.Id) ? "Добавить объект страхования" : string.Format("{0} {1}, {2}", Model.CarManufacture, Model.CarModel, Model.Release) + " - Азбука24";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
    var id = Request.RequestContext.RouteData.Values["id"];
}
<script type="text/javascript">
    var icons = JSON.parse('@Html.Raw(Model.Icons)');
    function GetModelsAuto() {
        $.getJSON('@Url.Action("GetModelsAuto", "Information", new { area = "" })' + "?modelAuto=" + $("#car-manufacture").val(), function (data) {
            var models = JSON.parse(data);
            var carModel = document.getElementById("car-model");
            var carModelLength = carModel.options.length;
            for (var i = 0; i < carModelLength; i++) {
                carModel.remove(carModel.options[i]);
            }
            for (var j = 0; j < models.length; j++) {
                carModel.options[j] = new Option(models[j], models[j]);
            }
            if ('@Model.CarModel') {
                $("#car-model").val('@Model.CarModel');
            }
        });
    };
    $(function () {
        if ($("#car-manufacture").val() != "---") {
            GetModelsAuto();
        }
        var existingFiles = JSON.parse('@Html.Raw(Model.ExistingFiles)');
        $('#fileupload').fileupload('option', 'done').call($('#fileupload'), null, { result: existingFiles });
        if ('@Request.Params["tab"]') {
            $("a[href='#" + '@Request.Params["tab"]' + "']").tab("show");
        }
    });
    function SendForm() {
        for (var i = 0; i < $(".template-download").length; i++) {
            $("#filesName").val($("#filesName").val() + $(".template-download td.preview a").eq(i).attr("title") + ';');
        }
        var postForm = document.getElementById("form1");
        postForm.appendChild(CreateHiddenField('Category', $("#category").val()));
        postForm.appendChild(CreateHiddenField('NameInsurant', $("#name").val()));
        postForm.submit();
    }
    function GetFiles() {
        var chk = $("tbody.files .delete input:checked").parents('td').siblings('.control').children('.btn-group').children('a');
        var names = [];
        for (var i = 0; i < chk.length; i++) {
            names.push(chk.eq(i).attr("download"));
        }
        var wnd = window.open();
        var formFiles = wnd.document.createElement('form');
        formFiles.action = '@Url.Action("GetFiles", "Cabinet")';
        formFiles.method = 'POST';
        formFiles.acceptCharset = 'utf-8';
        formFiles.appendChild(CreateHiddenField('objectId', '@Model.Id'));
        formFiles.appendChild(CreateHiddenField('names', JSON.stringify(names)));
        document.body.appendChild(formFiles);
        formFiles.submit();
        wnd.close();
    }
    function Calc(obj) {
        var objectData = new Object();
        objectData.CarManufacture = $("#car-manufacture").val();
        objectData.CarModel = $("#car-model").val();
        objectData.CategoryTs = $("#categoryts").val();
        objectData.Release = $("#car-release").val();
        objectData.Engine = $("#engine").val();
        objectData.Power = $("#power").val();
        objectData.Operation = $("#operation").val();
        objectData.Pts = $("#pts").val();
        objectData.ControlWheel = $("input[name=Controlwheel]:checked").val();
        objectData.Landing = $("#landing").val();
        objectData.MaxMass = $("#maxmass").val();
        objectData.Mass = $("#mass").val();
        var postform = document.createElement('form');
        postform.action = '@Url.Action("RedirectTo", "Information")';
        postform.method = 'post';
        postform.acceptCharset = 'utf-8';
        postform.appendChild(CreateHiddenField('objectData', JSON.stringify(objectData)));
        postform.appendChild(CreateHiddenField('id', '@id')); 
        if ($(obj).attr("name") == "tokasko") {
            postform.appendChild(CreateHiddenField('to', "kasko"));
        }
        if ($(obj).attr("name") == "toosago") {
            postform.appendChild(CreateHiddenField('to', "osago"));
        }
        document.body.appendChild(postform);
        postform.submit();
    }
</script>
<div class="row-fluid">
    @*<!--// Правая колонка -->*@
    <div class="page-header">
        <h2>
            @(string.IsNullOrEmpty(Model.Id) ? "Добавить объект страхования" : string.Format("{0} {1}, {2}", Model.CarManufacture, Model.CarModel, Model.Release))</h2>
    </div>
    @*<!--// Форма добавления авто-->*@
    <form class="form-horizontal">
    <div class="control-group">
        <label class="control-label" for="category">
            Объект страхования</label>
        <div class="controls">
            @Html.DropDownListFor(x => x.Category, Model.ListForCategory, new { id = "category", @class = "input-large" })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="name">
            Страхователь</label>
        <div class="controls">
            <div class="input-append">
                @Html.TextBoxFor(x => x.NameInsurant, new { @class = "input-large", id = "name", size = "16", placeholder = "Имя, фамилия" })<button class="btn" type="button" rel="tooltip" data-toggle="modal" onclick="$('#clients-list').modal('show');"
                    title="Выбрать из списка">
                    <i class="icon-list"></i>
                </button>
            </div>
        </div>
    </div>
    </form>
    <div class="tabbable">
        <ul class="nav nav-tabs">
            <li class="active"><a href="#tab0" data-toggle="tab">Сведения о ТС</a></li>
            <li><a href="#tab1" data-toggle="tab">Расчеты <span class="badge badge-success">@Model.Calculations.Count</span></a></li>
            <li><a href="#tab2" data-toggle="tab">Договоры <span class="badge badge-info">0</span></a></li>
            <li><a href="#tab3" data-toggle="tab">Файлы <span class="badge badge-important"></span>
            </a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane  active" id="tab0">
                @using (Html.BeginForm("AddObject", "Cabinet", FormMethod.Post, new { @class = "form-horizontal", id = "form1" }))
                {
                    @Html.HiddenFor(x => x.InsurantId)
                    @Html.Hidden("filesName")
                    <div class="row-fluid">
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label" for="categoryts">
                                    Категория ТС</label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.CategoryTs, Model.ListForCategoryTs, new { @class = "input-small", id = "categoryts" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="car-manufacture">
                                    <strong>Марка</strong></label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.CarManufacture, Model.ListForManufacture, new { @class = "input-large", id = "car-manufacture", onchange = "GetModelsAuto();" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="car-model">
                                    <strong>Модель</strong></label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.CarModel, Model.ListForModel, "---", new { @class = "input-large", id = "car-model" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="car-release">
                                    <strong>Год выпуска</strong></label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.Release, Model.ListForRelease, new { @class = "input-small", id = "car-release" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="engine">
                                    Объем двигателя</label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.Engine, Model.ListForEngine, new { @class = "input-large", id = "engine" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="power">
                                    Мощность</label>
                                <div class="controls">
                                    @Html.TextBoxFor(x => x.Power, new { @class = "input-large", id = "power" })
                                    <span class="help-inline">л.с.</span>
                                </div>
                            </div>
                        </div>
                        <div class="span6">
                            <div class="control-group">
                                <label class="control-label" for="operation">
                                    Начало эксплуатации</label>
                                <div class="controls">
                                    @Html.TextBoxFor(x => x.Operation, new { @class = "input-small date", id = "operation" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="pts">
                                    Дата выдачи ПТС</label>
                                <div class="controls">
                                    @Html.TextBoxFor(x => x.Pts, new { @class = "input-small date", id = "pts" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="controlwheel">
                                    Руль</label>
                                <div class="controls">
                                    <label class="radio inline">
                                        @Html.RadioButtonFor(x => x.Controlwheel, "Левый", new { id = "controlwheel", @checked = "checked" })
                                        Левый
                                    </label>
                                    <label class="radio inline">
                                        @Html.RadioButtonFor(x => x.Controlwheel, "Правый", new { id = "controlwheel1" })
                                        Правый
                                    </label>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="landing">
                                    Количество мест</label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.Landing, Model.ListForLanding, new { @class = "input-small", id = "landing" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="maxmass">
                                    Максимальная масса</label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.Maxmass, Model.ListForMaxmass, new { @class = "input-small", id = "maxmass" })
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="mass">
                                    Грузоподъемность</label>
                                <div class="controls">
                                    @Html.DropDownListFor(x => x.Mass, Model.ListForMass, new { @class = "input-small", id = "mass" })
                                </div>
                            </div>
                        </div>
                    </div>
                }
            </div>
            <div class="tab-pane" id="tab1">
                <p>
                    <a class="btn btn-large" data-toggle="modal" onclick="Calc(this);" name="tokasko"
                        href="javascript:void(0)">Расчитать КАСКО</a> <a onclick="Calc(this);" class="btn btn-large"
                            name="toosago" data-toggle="modal">Расчитать ОСАГО</a>
                </p>
                <table class="table table-bordered table-striped" id="mycalculate">
                    <thead>
                        <tr>
                            <th class="col-1">
                                <input type="checkbox" id="inlineCheckbox01" onchange="ChangeAllCheck();" title="Отметить все">
                            </th>
                            <th>
                                Риск
                            </th>
                            <th>
                                Номер
                            </th>
                            <th>
                                Дата расчета
                            </th>
                            <th>
                                Подтвердил
                            </th>
                            <th>
                                Управление
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @using (Html.BeginForm("DeleteCalculationsForObject", "Cabinet", FormMethod.Post, new { id = "form2" }))
                        {
                            @Html.Hidden("id")
                            foreach (var calc in Model.Calculations)
                            {
                            <tr>
                                <td class="col-1">
                                    <input type="checkbox" name="calculation" onchange="ChangeCheck(this);" value="@calc.Id" title="Отметить">
                                </td>
                                <td>
                                    @calc.Risk
                                </td>
                                <td>
                                    <a href="@(calc.TypeCalculation == "КАСКО" ? Url.Action("Kasko", "Information", new { id = calc.Id }) : Url.Action("OsagoResult", "Cabinet", new { id = calc.Id }))" target="_blank">@calc.UniqueNumber</a>
                                </td>
                                <td>
                                    @calc.CalculationDate.ToString("dd.MM.yyyy HH:mm")
                                </td>
                                <td>
                                    @calc.WhoConfirmed
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <button class="btn" rel="tooltip" data-original-title="Распечатать">
                                            <i class="icon-print"></i>
                                        </button>
                                        <button class="btn" type="button" href="javascript:void(0)" onclick="location.href = '@Url.Action("DeleteCalculation", new { deleteId = calc.Id, id = Model.Id })'" rel="tooltip" data-original-title="Удалить">
                                            <i class="icon-trash"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            }
                        }
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="100%">
                                <button class="btn" disabled="disabled" name="delete" onclick="$('#form2').submit();" state="watch">
                                    Удалить отмеченные</button>
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
            <div class="tab-pane" id="tab2">
                <table class="table table-bordered table-striped" id="partner-offices">
                    <thead>
                        <tr>
                            <th>
                                Наименование
                            </th>
                            <th>
                                Страхователь
                            </th>
                            <th>
                                Стоимость
                            </th>
                            <th>
                                Период действия
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>
                                <a href="#ссылка на БСО" target="_blank">Полис КАСКО 03310 2180965</a>
                            </td>
                            <td>
                                Зулифар Амор Аль Оглы
                            </td>
                            <td>
                                64 800 руб.
                            </td>
                            <td>
                                <ul class="unstyled">
                                    <li>от 28.12.2012 23:59</li>
                                    <li>до 28.12.2013 23:59</li>
                                </ul>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="tab-pane" id="tab3">
                @using (Html.BeginForm("UploadFiles", "Cabinet", FormMethod.Post, new { @class = "form-horizontal", id = "fileupload", enctype = "multipart/form-data" }))
                {
                    @Html.Hidden("id")
                    <fieldset>
                        <div class="fileupload-buttonbar">
                            <div class="span7">
                                <span class="btn btn-success fileinput-button"><span>Выбрать файлы</span>
                                    <input type="file" name="files[]" multiple>
                                </span>
                                <button type="submit" class="btn start">
                                    <span>Начать загрузку</span>
                                </button>
                                <button type="reset" class="btn cancel hide">
                                    <span>Остановить загрузку</span>
                                </button>
                            </div>
                            <div class="span5">
                                @*<!-- The global progress bar -->*@
                                <div class="progress progress-success progress-striped active fade">
                                    <div class="bar" style="width: 0%;">
                                    </div>
                                </div>
                            </div>
                        </div>
                        @*<!-- The loading indicator is shown during image processing -->*@
                        <div class="fileupload-loading">
                        </div>
                        <br>
                        @* <!-- The table listing the files available for upload/download -->*@
                        <table class="table table-striped">
                            <thead>
                                <th class="col-1 fileupload-buttonbar">
                                    <input type="checkbox" class="toggle">
                                    @*<input type="checkbox" name="delete" value="1" title="Отметить все">*@
                                </th>
                                <th>
                                    Превью
                                </th>
                                <th>
                                    Дата загрузки
                                </th>
                                <th>
                                    Размер
                                </th>
                                <th>
                                </th>
                                <th>
                                    Управление
                                </th>
                            </thead>
                            <tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery">
                            </tbody>
                        </table>
                    </fieldset>
                    <div class="fileupload-buttonbar">
                        <button type="button" class="btn " onclick="GetFiles();">
                            <span>Скачать отмеченные</span>
                        </button>
                        <button type="button" class="btn delete">
                            <span>Удалить отмеченные</span>
                        </button>
                    </div>
                }
            </div>
        </div>
    </div>
    <div class="form-actions">
        <button class="btn btn-primary btn-large" onclick="SendForm();" type="button">
            Сохранить изменения</button>
    </div>
    <!-- modal-gallery is the modal dialog used for the image gallery -->
    <!--div id="modal-gallery" class="modal modal-gallery hide fade">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">&times;</a>
            <h3 class="modal-title"></h3>
        </div>
        <div class="modal-body"><div class="modal-image"></div></div>
        <div class="modal-footer">
            <a class="btn btn-primary modal-next">
                <span>Next</span>
                <i class="icon-arrow-right icon-white"></i>
            </a>
            <a class="btn btn-info modal-prev">
                <i class="icon-arrow-left icon-white"></i>
                <span>Previous</span>
            </a>
            <a class="btn btn-success modal-play modal-slideshow" data-slideshow="5000">
                <i class="icon-play icon-white"></i>
                <span>Slideshow</span>
            </a>
            <a class="btn modal-download" target="_blank">
                <i class="icon-download"></i>
                <span>Download</span>
            </a>
        </div>
    </div-->
</div>
<script type="text/javascript">
    allCheckboxes = $("#mycalculate tbody .col-1 input[type=checkbox]");
</script>
@{Html.RenderPartial("_ListClients", Model.Clients);}
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
    <td>
        <input type="checkbox" name="delete" value="1" title="Отметить">
    </td>
    <td class="preview"><span class="fade thumbnail photo-preview"></span></td>
    <td>
        
    </td>
    <td class="size">
        <span>{%=o.formatFileSize(file.size)%}</span>
    </td>
    <td class="start">{% if (!o.options.autoUpload) { %}
                <button class="hide">
                </button>
    {% } %}</td>
    <td class="control cancel">
        <div class="btn-group">{% if (!i) { %}
            <button class="btn" type="button" data-type="{%=file.DeleteType%}" data-url="{%=file.DeleteUrl%}"
                rel="tooltip" title="Удалить">
                <i class="icon-trash icon-white"></i>               
            </button>
        </div>
            {% } %}</td>
</tr>
{% } %}
</script>
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% $("a[href='#tab3'] span").text($("a[href='#tab3'] span").text() ? parseInt($("a[href='#tab3'] span").text()) + o.files.length : o.files.length ); for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
    <td class="delete">
        <input type="checkbox" name="delete" value="1" title="Отметить">
    </td>
    <td class="preview">{% if (file.ThumbnailUrl) { %}
        <a rel="gallery" class="thumbnail photo-preview" href="{%=file.ReviewUrl%}" 
            title="{%=file.Name%}" downloadurl="{%=file.Url%}">
            <img src="{%=file.ThumbnailUrl%}" alt="{%=file.Name%}">
        </a>
    {% } %}</td>
    <td>
        {%=file.DateUpload%}
    </td>
    <td class="size">
        <span>{%=o.formatFileSize(file.Size)%}</span>
    </td>
    <td>
    </td>
    <td class="control">
        <div class="btn-group delete">
            <a class="btn" target="_blank" href="{%=file.Url%}"
                download="{%=file.Name%}" rel="tooltip" title="Скачать">
                <i class="icon-download-alt"></i></a>
            <button class="btn" data-type="{%=file.DeleteType%}" data-url="{%=file.DeleteUrl%}"
                rel="tooltip" title="Удалить">
                <i class="icon-trash icon-white"></i>                
            </button>           
        </div>
    </td>
</tr>
{% } %}
</script>
@*<script id="template-download456456456" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        {% if (file.error) { %}
            <td></td>
            <td class="name"><span>{%=file.Name%}</span></td>
            <td class="size"><span>{%=o.formatFileSize(file.Size)%}</span></td>
            <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
        {% } else { %}
            <td class="preview">{% if (file.ThumbnailUrl) { %}
                <a href="{%=file.Url%}" title="{%=file.Name%}" rel="gallery" download="{%=file.Name%}"><img src="{%=file.ThumbnailUrl%}"></a>
            {% } %}</td>
            <td class="name">
                <a target="_blank" href="{%=file.Url%}" title="{%=file.Name%}" rel="{%=file.ThumbnailUrl&&'gallery'%}" download="{%=file.Name%}">{%=file.Name%}</a>
            </td>
            <td class="size"><span>{%=o.formatFileSize(file.Size)%}</span></td>
            <td colspan="2"></td>
        {% } %}
        <td class="delete">
            <button class="btn btn-danger" data-type="{%=file.DeleteType%}" data-url="{%=file.DeleteUrl%}">
                <i class="icon-trash icon-white"></i>
                <span>{%=locale.fileupload.destroy%}</span>
            </button>
            <input type="checkbox" name="delete" value="1">
        </td>
    </tr>
{% } %}
</script>*@
<!--// Окно галереи объектов -->
<div id="modal-gallery" class="modal modal-gallery hide">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">&times;</a>
        <h3 class="modal-title">
        </h3>
    </div>
    <div class="modal-body">
        <div class="modal-image">
        </div>
    </div>
    <div class="modal-footer">
        <a href="" download="7b3b8b5f-3842-406f-b5a0-df2a5888dcaf.jpg" class="btn btn-success modal-download"
            target="_blank">Скачать</a>
    </div>
</div>
<!-- Окно галереи объектов //-->
